//
//  HOTableViewCell.m
//  WeiDu_1_0
//
//  Created by foguo-mac-1 on 1/12/16.
//  Copyright © 2016 ShenOu. All rights reserved.
//

#import "HOTableViewCell.h"
#import "HODefaultImage.h"
#import "HOImageMgr.h"
#import "HOUtils.h"

@interface HOTableViewCell()


@end

@implementation HOTableViewCell

- (void)initViewsWithHeight:(CGFloat)height withWidth:(CGFloat)width
{
	cellHeight = height;
	cellWidth = width;
	if(isInited)
		return;
	isInited = YES;
	
	self.accessoryType = UITableViewCellAccessoryNone;
	bgView = [[UIView alloc]
			  initWithFrame:CGRectMake(0,
									   0,
									   cellWidth,
									   cellHeight)];
	[bgView setBackgroundColor:[UIColor whiteColor]];
	[self.contentView addSubview:bgView];
	
	iconImgView = [[UIImageView alloc]init];
	[self.contentView addSubview:iconImgView];
	
	contentLbl = [[UILabel alloc]
				  initWithFrame:CGRectMake(HO_HORIZONAL_PADDING,
										   (cellHeight - 22) / 2,
										   cellWidth - 44 - 30 -  100,
										   22)];
	contentLbl.textColor = TEXT_COLOR_181818;
	contentLbl.font = [UIFont systemFontOfSize:15];
	[self.contentView addSubview:contentLbl];
	
	nextImgView = [[UIImageView alloc]
				   initWithFrame:CGRectMake(cellWidth - 15 - HO_HORIZONAL_PADDING,
											(cellHeight - [[HOImageMgr sharedInstance] getGoImage].size.width) / 2,
											[[HOImageMgr sharedInstance] getGoImage].size.width,
											[[HOImageMgr sharedInstance] getGoImage].size.height)];
	nextImgView.image = [[HOImageMgr sharedInstance] getGoImage];
//	[self.contentView addSubview:nextImgView];
}

- (void)dealloc
{
//	NSLog(@"dealloc1");
	if(bgView)
	{
		[HOUtils removeFromSuperViewForViews:bgView];
		[bgView release];
		bgView = nil;
	}
	
	if(iconImgView)
	{
		[HOUtils removeFromSuperViewForViews:iconImgView];
		[iconImgView release];
		iconImgView = nil;
	}
	
	
	if(iconImgView)
	{
		[HOUtils removeFromSuperViewForViews:iconImgView];
		[iconImgView release];
		iconImgView = nil;
	}
	
	
	if(contentLbl)
	{
		[HOUtils removeFromSuperViewForViews:contentLbl];
		[contentLbl release];
		contentLbl = nil;
	}
	[super dealloc];
}

- (void)removeAllContentView
{
	NSArray *views = [NSArray arrayWithArray:self.contentView.subviews];
	for(UIView *view in views)
	{
		[view removeFromSuperview];
	}
}

- (void)setIconWithName:(NSString *)name;
{
	if(name == nil || name.length == 0)
	{
		
		iconImgView.frame = CGRectMake(HO_HORIZONAL_PADDING,
									   0,
									   0,
									   0);
		return;
	}
	UIImage *image = [UIImage imageNamed:name];
//	iconImgView.layer.borderWidth = 1;
	iconImgView.frame = CGRectMake(HO_HORIZONAL_PADDING,
								   (cellHeight - image.size.height) / 2,
								   image.size.width,
								   image.size.height);
	iconImgView.image = image;
	if([iconImgView superview] == nil)
	{
		[self.contentView addSubview:iconImgView];
	}
}

- (void)setContent:(NSString *)content
{
	contentLbl.text = content;
}

- (NSString *)getContent
{
	return contentLbl.text;
}

- (void)awakeFromNib {
	// Initialization code
	[super awakeFromNib];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
	[super setSelected:selected animated:animated];
	
	// Configure the view for the selected state
}

- (void)setHighlighted:(BOOL)highlighted
{
	if(bgView)
	[bgView setBackgroundColor:highlighted ? [UIColor grayColor] : [UIColor whiteColor]];
}



@end
